package com.feri.rbacsys.controller.finance;


import com.feri.rbacsys.entity.finance.DataBusinessType;
import com.feri.rbacsys.service.intf.finance.DataBusinessTypeService;
import com.feri.rbacsys.vo.R;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (DataBusinessType)表控制层
 *
 * @author makejava
 * @since 2023-03-28 08:28:02
 */
@RestController
@RequestMapping("dataBusinessType")
@Api(tags = "收支类型接口")
public class DataBusinessTypeController{
    /**
     * 服务对象
     */
    @Resource
    private DataBusinessTypeService dataBusinessTypeService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @return 所有数据
     */
    @PreAuthorize("hasAuthority('databu:page')")
    @GetMapping("page.do")
    public R queryPage(int page, int size) {
        return dataBusinessTypeService.queryPage(page, size);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PreAuthorize("hasAuthority('databu:one')")
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return R.ok(this.dataBusinessTypeService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param dataBusinessType 实体对象
     * @return 新增结果
     */
    @PreAuthorize("hasAuthority('databu:insert')")
    @PostMapping("insert.do")
    public R insert(@RequestBody DataBusinessType dataBusinessType) {
        return R.ok(this.dataBusinessTypeService.save(dataBusinessType));
    }

    /**
     * 修改数据
     *
     * @param dataBusinessType 实体对象
     * @return 修改结果
     */
    @PostMapping("update.do")
    public R update(@RequestBody DataBusinessType dataBusinessType) {
        return R.ok(this.dataBusinessTypeService.updateById(dataBusinessType));
    }

    /**
     * 删除数据
     *
     * @return 删除结果
     */
    @PreAuthorize("hasAuthority('databu:del')")
    @GetMapping
    public R delete(String id) {
        return R.ok(this.dataBusinessTypeService.removeById(id));
    }
}

